package service.impl;

import common.consts.Accounts;
import common.consts.Consts;
import dao.AccountDao;
import domain.Account;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import service.LogoutService;
import service.ServiceResponse;

/**
 * Created by Administrator on 2015/7/2.
 */

@Service

public class LogoutServiceImpl extends ServiceBase implements LogoutService {


    @Autowired
    private AccountDao accountDao;


    @Override
    @Transactional
    public ServiceResponse logout(long accountId) {
        Account account = accountDao.get(accountId);
        if (account == null) {
            return ServiceResponse.fail(Consts.i18nKey.UNKNOWN_USER);

        }

        account.setStatus(Accounts.Status.OFFLINE.name());


        accountDao.updateAccountStatus(account.getId(), Accounts.Status.OFFLINE);

        return ServiceResponse.success();


    }
}
